/*
 * $Id: EtherAddress.cc,v 1.2 2005-05-11 15:43:47 bacon Exp $
 */

#include <xpp/net/EtherAddress.h>
#include <xp/bas/memory.h>
#include <xp/bas/stdio.h>

namespace xpp
{
	namespace net
	{

		EtherAddress::EtherAddress ()
		{
			xp_memset (&address_storage, 0, xp_sizeof(address_storage));
		}

		EtherAddress::EtherAddress (const EtherAddress& addr)
		{
			xp_memcpy (&address_storage, 
				&addr.address_storage, xp_sizeof(address_storage));
		}

		EtherAddress::EtherAddress (const xp_byte_t* addr)
		{
			xp_memcpy (&address_storage, addr, xp_sizeof(address_storage));
		}

		EtherAddress& EtherAddress::operator= (const EtherAddress& addr)
		{
			xp_memcpy (&address_storage, 
				&addr.address_storage, xp_sizeof(address_storage));
			return *this;
		}

		EtherAddress& EtherAddress::operator= (const xp_byte_t* addr)
		{
			xp_memcpy (&address_storage, addr, xp_sizeof(address_storage));
			return *this;
		}
	
		xpp::bas::String EtherAddress::toString () const
		{
			xp_char_t buf[18];
			xp_sprintf (buf, xp_countof(buf),
				XP_TEXT("%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X"),
				address_storage[0], address_storage[1],
				address_storage[2], address_storage[3],
				address_storage[4], address_storage[5]);	
			return xpp::bas::String(buf);
		}
	}
}
